$(document).ready(function () {
    $('#nav-username').html('' + getCookie('u-name') + '')
    if (getCookie('login-usertype') == "student") {
        $('#navbox').html(`
            <span>
                <div class="btn-group">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                    <ul class="dropdown-menu" style="right:0;">
                        <li><a href="#" id="public-update">修改密码</a></li>
                        <li><a href="Personnel-list.html">答辩列表</a></li>
                        <li><a href="details.html">我的答辩</a></li>
                        <li><a href="#" id="askfordefence">申请答辩</a></li>
                        <li role="separator" class="divider" style="margin:0"></li>
                        <li><a href="#"  id="cancel">注销</a></li>
                    </ul>
                </div>
            </span>
            <span id="nav-position">同学</span>
            <span id="nav-username" style="color: blue;">` + getCookie('u-name') + `</span>
        `)
    }
    if (getCookie('login-usertype') == "clerk") {
        $('#navbox').html(`
            <span>
                <div class="btn-group">
                    <a href="#" class="dropdown-toggle" data-toggle="dropdown"><span class="caret"></span></a>
                    <ul class="dropdown-menu" style="right:0;">
                        <li><a href="#" id="public-update">修改密码</a></li>
                        <li><a href="Personnel-list.html">答辩列表</a></li>
                        <li role="separator" class="divider" style="margin:0"></li>
                        <li><a href="#"  id="cancel">注销</a></li>
                    </ul>
                </div>
            </span>
            <span id="nav-position">书记员</span>
            <span id="nav-username" style="color: blue;">` + getCookie('u-name') + `</span>
        `)
    }
    //获取列表
    $.ajax({
        type: 'GET',
        url: '/student/seeDefence',
        xhrFields: {
            withCredentials: true
        },
        success: function (data) {
            console.log(data)
            if (data.status == 0) {
                var array=data.groupA
                var array1=data.groupB
                var Ashuzu = []
                var Bshuzu = []
                $('#list-Agroup').html('')
                for (var i = 0; i < array.length; i++) {
                    Ashuzu = array[i].split(',')
                    $('#list-Agroup').append(`
                        <li>
                            <span>`+(i+1)+`</span>
                            <span>`+Ashuzu[0]+`</span>
                            <span value="`+Ashuzu[2]+`">`+Ashuzu[1]+`</span>
                            <span class="personal-status">`+Ashuzu[3]+`</span>
                        </li>
                    `)    
                }
                $('#list-Bgroup').html('')
                for (var i = 0; i < array1.length; i++) {
                    Bshuzu = array1[i].split(',')
                    $('#list-Bgroup').append(`
                        <li>
                            <span>`+(i+1)+`</span>
                            <span>`+Bshuzu[0]+`</span>
                            <span value="`+Bshuzu[2]+`">`+Bshuzu[1]+`</span>
                            <span class="personal-status">`+Bshuzu[3]+`</span>
                        </li>
                    `)    
                }
            } else {
                $('#myModal-public').modal({})
                $('#myModal-public .modal-header p').html('获取分组列表失败')
                $('#myModal-public-body').html(data.msg)
                 $('#myModal-public .modal-footer').html(
                `   
                    <button type="button" class="btn" data-dismiss="modal" style="padding: 2px 20px;">关闭</button>    
                `
            )
            }
        },
})
    $('.personal-status').each(function () {
        switch ($(this).html()) {
            case "已答辩":
                $(this).css('color', 'green')
                break;
            case "答辩中":
                $(this).css('color', 'blue')
                break;
            case "未答辩":
                $(this).css('color', 'black')
                break;
            case "缺考":
                $(this).css('color', 'red')
                break;
        }
    })

    $('.list-divwrap li').off('click').click(function () {
        console.log($(this).find('span').eq(2).attr('value'))
        setCookie('stuid', $(this).find('span').eq(2).attr('value'))
        window.location.href = "details.html"
    })

})